<?php 
namespace Admin\Controller;
use Think\Controller;

/**
 * 商品分类控制器
 */
class GoodsCatsController extends Controller {
	/**
	 * 分页列表
	 */
	public function index() {
		$m = D('Admin/GoodsCats');
		$list = $m->getCatAndChild();
		$this->assign('list',$list);
		$this->display("/goodscats/list");
	}

	/**
	 * 列表查询
	 */
    public function queryByList(){
    
		$m = D('Admin/GoodsCats');
		$list = $m->queryByList(I('id'));
		$rs = array();
		$rs['status'] = 1;
		$rs['list'] = $list;
		$this->ajaxReturn($rs);
	}


	/**
	 * 跳到新增、编辑页面
	 */
	public function toEdit() {

	    $m = D('Admin/GoodsCats');
    	$object = array();
    	if(I('id',0)>0){
    		$object = $m->get(I('id',0));
    	}else{
    		
    		if(I('parentId',0)>0){
    		   $object = $m->get(I('parentId',0));
    		   $object['parentId'] = $object['catid'];
    		   $object['catName'] = '';
    		   $object['catSort'] = 0;
    		   $object['catId'] = 0;
    		}else{
    		   $object = $m->getModel();
    		}
    	}
    	// dump($object');
    	$this->assign('object',$object);
		$this->view->display('/goodscats/edit');
	}
	
	/**
	 * 新增、修改操作，数据收集。
	 */
	public function edit() {

		$m = D('Admin/GoodsCats');
		$rs = array();
		if(I('id',0)>0){
			
			$rs = $m->edit();
		}else{
			
			$rs = $m->insert();
		}
		$this->ajaxReturn($rs);
	}

	/**
	 * 修改名称
	 */
	public function editName(){
		
		$m = D('Admin/GoodsCats');
    	$rs = array('status'=>-1);
    	if(I('id',0)>0){
    		
    		$rs = $m->editName();
    	}
    	$this->ajaxReturn($rs);
	}

	/**
	 * 删除操作
	 */
	public function del(){
		
		$m = D('Admin/GoodsCats');
    	$rs = $m->del();
    	$this->ajaxReturn($rs);
	}

	/**
	 * 显示商品是否显示/隐藏
	 */
	public function editiIsShow(){
	 	
	 	$m = D('Admin/GoodsCats');
		$rs = $m->editiIsShow();
		$this->ajaxReturn($rs);
	}

}
 ?>